// Copyright (C) 1953-2022 NUDT
// Verilog module name - measure_request
// Version: V4.1.0.20221206
// Created:
//         by - fenglin
////////////////////////////////////////////////////////////////////////////
// Description:
//         
///////////////////////////////////////////////////////////////////////////

`timescale 1ns/1ps

module measure_request
#(
parameter local_module_id = 12'd0,
parameter PTP_RX_OFFSET_XGMII = 16'd131,
parameter PTP_TX_OFFSET_XGMII = 16'd58,     
parameter PTP_RX_OFFSET_GMII = 16'd192,
parameter PTP_TX_OFFSET_GMII = 16'd72, 
parameter clk_period = {8'd8,41'h0}//8ns
)
(
    i_clk  ,
    i_rst_n,
	
    
    iv_data                               ,
	i_data_wr                             ,
	
	iv_measure_period                     ,
	iv_measure_responder_wait_time        ,
	iv_port_ptp_enabled                   ,
	iv_hcp_mid                            ,
	iv_mea_clk                            ,

	ov_data                               ,
	o_data_wr                             ,
	  
	ov_t1                  ,
	ov_t2                  ,
	ov_t3                  ,
	ov_t4                  ,
	ov_timestamps_port_id  ,
	o_timestamps_valid     ,
	
	ov_link_delay          ,
	ov_link_delay_id       ,
	o_link_delay_valid     ,     		
	
	i_osm_req_tx_pulse_p0  ,
	i_osm_resp_rx_pulse_p0 ,
	i_osm_req_tx_pulse_p1  ,
	i_osm_resp_rx_pulse_p1 ,
	i_osm_req_tx_pulse_p2  ,
	i_osm_resp_rx_pulse_p2 ,
	i_osm_req_tx_pulse_p3  ,
	i_osm_resp_rx_pulse_p3 ,
	i_osm_req_tx_pulse_p4  ,
	i_osm_resp_rx_pulse_p4 ,
	i_osm_req_tx_pulse_p5  ,
	i_osm_resp_rx_pulse_p5 ,
	i_osm_req_tx_pulse_p6  ,
	i_osm_resp_rx_pulse_p6 ,
	i_osm_req_tx_pulse_p7  ,
	i_osm_resp_rx_pulse_p7 ,
	i_osm_req_tx_pulse_p8  ,
	i_osm_resp_rx_pulse_p8 ,
	i_osm_req_tx_pulse_p9  ,
	i_osm_resp_rx_pulse_p9 ,
	i_osm_req_tx_pulse_p10  ,
	i_osm_resp_rx_pulse_p10 ,
	i_osm_req_tx_pulse_p11  ,
	i_osm_resp_rx_pulse_p11 ,
	i_osm_req_tx_pulse_p12  ,
	i_osm_resp_rx_pulse_p12 ,
	i_osm_req_tx_pulse_p13  ,
	i_osm_resp_rx_pulse_p13 ,
	i_osm_req_tx_pulse_p14  ,
	i_osm_resp_rx_pulse_p14 ,
	i_osm_req_tx_pulse_p15  ,
	i_osm_resp_rx_pulse_p15 ,
	i_osm_req_tx_pulse_p16  ,
	i_osm_resp_rx_pulse_p16 ,
	i_osm_req_tx_pulse_p17  ,
	i_osm_resp_rx_pulse_p17 ,
	i_osm_req_tx_pulse_p18  ,
	i_osm_resp_rx_pulse_p18 ,
	i_osm_req_tx_pulse_p19  ,
	i_osm_resp_rx_pulse_p19 ,
	i_osm_req_tx_pulse_p20  ,
	i_osm_resp_rx_pulse_p20 ,
	i_osm_req_tx_pulse_p21  ,
	i_osm_resp_rx_pulse_p21 ,
	i_osm_req_tx_pulse_p22  ,
	i_osm_resp_rx_pulse_p22 ,
	i_osm_req_tx_pulse_p23  ,
	i_osm_resp_rx_pulse_p23 ,
	i_osm_req_tx_pulse_p24  ,
	i_osm_resp_rx_pulse_p24 ,	
	i_osm_req_tx_pulse_p25  ,
	i_osm_resp_rx_pulse_p25 ,
	i_osm_req_tx_pulse_p26  ,
	i_osm_resp_rx_pulse_p26 ,
	i_osm_req_tx_pulse_p27  ,
	i_osm_resp_rx_pulse_p27 ,
	i_osm_req_tx_pulse_p28  ,
	i_osm_resp_rx_pulse_p28 ,
	i_osm_req_tx_pulse_p29  ,
	i_osm_resp_rx_pulse_p29 ,
	i_osm_req_tx_pulse_p30  ,
	i_osm_resp_rx_pulse_p30 ,
	i_osm_req_tx_pulse_p31  ,
	i_osm_resp_rx_pulse_p31 ,		

	ov_measure_req_tx_cnt_p0              ,
	ov_measure_resp_rx_timeout_cnt_p0     ,	
	ov_measure_req_tx_cnt_p1              ,
	ov_measure_resp_rx_timeout_cnt_p1     ,	
	ov_measure_req_tx_cnt_p2              ,
	ov_measure_resp_rx_timeout_cnt_p2     ,	
	ov_measure_req_tx_cnt_p3              ,
	ov_measure_resp_rx_timeout_cnt_p3     ,	
	ov_measure_req_tx_cnt_p4              ,
	ov_measure_resp_rx_timeout_cnt_p4     ,	
	ov_measure_req_tx_cnt_p5              ,
	ov_measure_resp_rx_timeout_cnt_p5     ,	
	ov_measure_req_tx_cnt_p6              ,
	ov_measure_resp_rx_timeout_cnt_p6     ,	
	ov_measure_req_tx_cnt_p7              ,
	ov_measure_resp_rx_timeout_cnt_p7     ,	
	ov_measure_req_tx_cnt_p8              ,
	ov_measure_resp_rx_timeout_cnt_p8     ,	
	ov_measure_req_tx_cnt_p9              ,
	ov_measure_resp_rx_timeout_cnt_p9     ,	
	ov_measure_req_tx_cnt_p10             ,
	ov_measure_resp_rx_timeout_cnt_p10    ,	
	ov_measure_req_tx_cnt_p11             ,
	ov_measure_resp_rx_timeout_cnt_p11    ,	
	ov_measure_req_tx_cnt_p12             ,
	ov_measure_resp_rx_timeout_cnt_p12    ,	
	ov_measure_req_tx_cnt_p13             ,
	ov_measure_resp_rx_timeout_cnt_p13    ,	
	ov_measure_req_tx_cnt_p14             ,
	ov_measure_resp_rx_timeout_cnt_p14    ,	
	ov_measure_req_tx_cnt_p15             ,
	ov_measure_resp_rx_timeout_cnt_p15    ,	
	ov_measure_req_tx_cnt_p16             ,
	ov_measure_resp_rx_timeout_cnt_p16    ,	
	ov_measure_req_tx_cnt_p17             ,
	ov_measure_resp_rx_timeout_cnt_p17    ,	
	ov_measure_req_tx_cnt_p18             ,
	ov_measure_resp_rx_timeout_cnt_p18    ,	
	ov_measure_req_tx_cnt_p19             ,
	ov_measure_resp_rx_timeout_cnt_p19    ,	
	ov_measure_req_tx_cnt_p20             ,
	ov_measure_resp_rx_timeout_cnt_p20    ,	
	ov_measure_req_tx_cnt_p21             ,
	ov_measure_resp_rx_timeout_cnt_p21    ,	
	ov_measure_req_tx_cnt_p22             ,
	ov_measure_resp_rx_timeout_cnt_p22    ,	
	ov_measure_req_tx_cnt_p23             ,
	ov_measure_resp_rx_timeout_cnt_p23    ,
    ov_measure_req_tx_cnt_p24             ,
	ov_measure_resp_rx_timeout_cnt_p24    ,
    ov_measure_req_tx_cnt_p25             ,
	ov_measure_resp_rx_timeout_cnt_p25    ,
	ov_measure_req_tx_cnt_p26             ,
	ov_measure_resp_rx_timeout_cnt_p26    ,
	ov_measure_req_tx_cnt_p27             ,
	ov_measure_resp_rx_timeout_cnt_p27    ,
	ov_measure_req_tx_cnt_p28             ,
	ov_measure_resp_rx_timeout_cnt_p28    ,
	ov_measure_req_tx_cnt_p29             ,
	ov_measure_resp_rx_timeout_cnt_p29    ,
	ov_measure_req_tx_cnt_p30             ,
	ov_measure_resp_rx_timeout_cnt_p30    ,
	ov_measure_req_tx_cnt_p31             ,
	ov_measure_resp_rx_timeout_cnt_p31    ,

    ov_req_sequence    
);

// I/O
// clk & rst
input                   i_clk;
input                   i_rst_n; 
// pkt input
input      [3:0]        iv_measure_period                     ;
input	   [2:0]        iv_measure_responder_wait_time        ;
input	   [31:0]       iv_port_ptp_enabled                   ;		                						        
input      [11:0]       iv_hcp_mid                            ;
input      [95:0]       iv_mea_clk                            ;

input	   [8:0]	    iv_data        ;
input	         	    i_data_wr      ;
// pkt output to NMA
output     [8:0]	    ov_data        ;
output    	            o_data_wr      ;
// pkt output to osp
input                  i_osm_req_tx_pulse_p0   ;
input                  i_osm_resp_rx_pulse_p0  ;
input                  i_osm_req_tx_pulse_p1   ;
input                  i_osm_resp_rx_pulse_p1  ;
input                  i_osm_req_tx_pulse_p2   ;
input                  i_osm_resp_rx_pulse_p2  ;
input                  i_osm_req_tx_pulse_p3   ;
input                  i_osm_resp_rx_pulse_p3  ;
input                  i_osm_req_tx_pulse_p4   ;
input                  i_osm_resp_rx_pulse_p4  ;
input                  i_osm_req_tx_pulse_p5   ;
input                  i_osm_resp_rx_pulse_p5  ;
input                  i_osm_req_tx_pulse_p6   ;
input                  i_osm_resp_rx_pulse_p6  ;
input                  i_osm_req_tx_pulse_p7   ;
input                  i_osm_resp_rx_pulse_p7  ;
input                  i_osm_req_tx_pulse_p8   ;
input                  i_osm_resp_rx_pulse_p8  ;
input                  i_osm_req_tx_pulse_p9   ;
input                  i_osm_resp_rx_pulse_p9  ;
input                  i_osm_req_tx_pulse_p10  ;
input                  i_osm_resp_rx_pulse_p10 ;
input                  i_osm_req_tx_pulse_p11  ;
input                  i_osm_resp_rx_pulse_p11 ;
input                  i_osm_req_tx_pulse_p12  ;
input                  i_osm_resp_rx_pulse_p12 ;
input                  i_osm_req_tx_pulse_p13  ;
input                  i_osm_resp_rx_pulse_p13 ;
input                  i_osm_req_tx_pulse_p14  ;
input                  i_osm_resp_rx_pulse_p14 ;
input                  i_osm_req_tx_pulse_p15  ;
input                  i_osm_resp_rx_pulse_p15 ;
input                  i_osm_req_tx_pulse_p16  ;
input                  i_osm_resp_rx_pulse_p16 ;
input                  i_osm_req_tx_pulse_p17  ;
input                  i_osm_resp_rx_pulse_p17 ;
input                  i_osm_req_tx_pulse_p18  ;
input                  i_osm_resp_rx_pulse_p18 ;
input                  i_osm_req_tx_pulse_p19  ;
input                  i_osm_resp_rx_pulse_p19 ;
input                  i_osm_req_tx_pulse_p20  ;
input                  i_osm_resp_rx_pulse_p20 ;
input                  i_osm_req_tx_pulse_p21  ;
input                  i_osm_resp_rx_pulse_p21 ;
input                  i_osm_req_tx_pulse_p22  ;
input                  i_osm_resp_rx_pulse_p22 ;
input                  i_osm_req_tx_pulse_p23  ;
input                  i_osm_resp_rx_pulse_p23 ;
input                  i_osm_req_tx_pulse_p24  ;
input                  i_osm_resp_rx_pulse_p24 ;
input                  i_osm_req_tx_pulse_p25  ;
input                  i_osm_resp_rx_pulse_p25 ;
input                  i_osm_req_tx_pulse_p26  ;
input                  i_osm_resp_rx_pulse_p26 ;
input                  i_osm_req_tx_pulse_p27  ;
input                  i_osm_resp_rx_pulse_p27 ;
input                  i_osm_req_tx_pulse_p28  ;
input                  i_osm_resp_rx_pulse_p28 ;
input                  i_osm_req_tx_pulse_p29  ;
input                  i_osm_resp_rx_pulse_p29 ;
input                  i_osm_req_tx_pulse_p30  ;
input                  i_osm_resp_rx_pulse_p30 ;
input                  i_osm_req_tx_pulse_p31  ;
input                  i_osm_resp_rx_pulse_p31 ;

output     [15:0]       ov_measure_req_tx_cnt_p0              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p0     ;	
output     [15:0]       ov_measure_req_tx_cnt_p1              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p1     ;	
output     [15:0]       ov_measure_req_tx_cnt_p2              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p2     ;	
output     [15:0]       ov_measure_req_tx_cnt_p3              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p3     ;	
output     [15:0]       ov_measure_req_tx_cnt_p4              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p4     ;	
output     [15:0]       ov_measure_req_tx_cnt_p5              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p5     ;	
output     [15:0]       ov_measure_req_tx_cnt_p6              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p6     ;	
output     [15:0]       ov_measure_req_tx_cnt_p7              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p7     ;	
output     [15:0]       ov_measure_req_tx_cnt_p8              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p8     ;	
output     [15:0]       ov_measure_req_tx_cnt_p9              ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p9     ;	
output     [15:0]       ov_measure_req_tx_cnt_p10             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p10    ;	
output     [15:0]       ov_measure_req_tx_cnt_p11             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p11    ;	
output     [15:0]       ov_measure_req_tx_cnt_p12             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p12    ;	
output     [15:0]       ov_measure_req_tx_cnt_p13             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p13    ;	
output     [15:0]       ov_measure_req_tx_cnt_p14             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p14    ;	
output     [15:0]       ov_measure_req_tx_cnt_p15             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p15    ;	
output     [15:0]       ov_measure_req_tx_cnt_p16             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p16    ;	
output     [15:0]       ov_measure_req_tx_cnt_p17             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p17    ;	
output     [15:0]       ov_measure_req_tx_cnt_p18             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p18    ;	
output     [15:0]       ov_measure_req_tx_cnt_p19             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p19    ;	
output     [15:0]       ov_measure_req_tx_cnt_p20             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p20    ;	
output     [15:0]       ov_measure_req_tx_cnt_p21             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p21    ;	
output     [15:0]       ov_measure_req_tx_cnt_p22             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p22    ;	
output     [15:0]       ov_measure_req_tx_cnt_p23             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p23    ;
output     [15:0]       ov_measure_req_tx_cnt_p24             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p24    ;
output     [15:0]       ov_measure_req_tx_cnt_p25             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p25    ;
output     [15:0]       ov_measure_req_tx_cnt_p26             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p26    ;
output     [15:0]       ov_measure_req_tx_cnt_p27             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p27    ;
output     [15:0]       ov_measure_req_tx_cnt_p28             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p28    ;
output     [15:0]       ov_measure_req_tx_cnt_p29             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p29    ;
output     [15:0]       ov_measure_req_tx_cnt_p30             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p30    ;
output     [15:0]       ov_measure_req_tx_cnt_p31             ;
output     [15:0]       ov_measure_resp_rx_timeout_cnt_p31    ;	
// pkt output to pip
output     [95:0]       ov_t1                   ;
output     [95:0]       ov_t2                   ;	
output     [95:0]       ov_t3                   ;		
output     [95:0]       ov_t4                   ;
output     [4:0]        ov_timestamps_port_id           ;	
output                  o_timestamps_valid              ;
					    
output     [27:0]       ov_link_delay                   ;
output     [4:0]        ov_link_delay_id                ;	
output                  o_link_delay_valid              ;

output     [15:0]       ov_req_sequence                 ;	
/////////////////////////////////////
//wire         [23:0]     wv_local_cnt_rx_opd2ipp;
wire         [15:0]     wv_eth_type_opd2ipp    ;
wire         [7:0]      wv_tsmp_type_opd2ipp   ;
wire         [7:0]      wv_tsmp_subtype_opd2ipp;
wire         [7:0]      wv_osm_id_opd2ipp;
wire         [8:0]      wv_data_opd2ipp;
wire                    w_data_wr_opd2ipp;

wire         [8:0]      wv_data_ipp2ope  ;
wire                    w_data_wr_ipp2ope;
wire         [4:0]      wv_osm_id_ipp2ope;
wire                    w_first_byte_valid_ipp2ope;

wire                    w_measure_req_irt2ipp;

wire         [95:0]     wv_t1_itr2ldc                   ;	
wire         [95:0]     wv_t4_itr2ldc                   ;
wire         [4:0]      wv_port_id_itr2ldc              ;	
wire                    w_t1_valid_itr2ldc              ;
wire                    w_t4_valid_itr2ldc              ;

wire         [95:0]	    wv_t2_ipp2ldc            ;
wire         [95:0]     wv_t3_ipp2ldc            ;
wire                    w_t2_wr_ipp2ldc          ;
wire                    w_t3_wr_ipp2ldc          ;
wire                    w_pdelay_pkt_waittimeout_flag_ipp2ldc;
initiator_request_timing
#(
.clk_period(clk_period)
)  
initiator_request_timing_inst
(
        .i_clk                  (i_clk  ),
        .i_rst_n                (i_rst_n),
 
        .iv_port_ptp_enabled	(iv_port_ptp_enabled),
        .iv_measure_period      (iv_measure_period  ),		
 
        .o_measure_req          (w_measure_req_irt2ipp)
);

initiator_timestamps_record
#(
.PTP_RX_OFFSET_XGMII(PTP_RX_OFFSET_XGMII),
.PTP_TX_OFFSET_XGMII(PTP_TX_OFFSET_XGMII),
.PTP_RX_OFFSET_GMII(PTP_RX_OFFSET_GMII),
.PTP_TX_OFFSET_GMII(PTP_TX_OFFSET_GMII),
.clk_period(clk_period)
)  
initiator_timestamps_record_inst
(
        .i_clk                   (i_clk  ),
        .i_rst_n                 (i_rst_n),
	 
        .iv_mea_clk         	 (iv_mea_clk),
 
		.i_osm_req_tx_pulse_p0   (i_osm_req_tx_pulse_p0  ),
		.i_osm_resp_rx_pulse_p0  (i_osm_resp_rx_pulse_p0 ),
		.i_osm_req_tx_pulse_p1   (i_osm_req_tx_pulse_p1  ),
		.i_osm_resp_rx_pulse_p1  (i_osm_resp_rx_pulse_p1 ),
		.i_osm_req_tx_pulse_p2   (i_osm_req_tx_pulse_p2  ),
		.i_osm_resp_rx_pulse_p2  (i_osm_resp_rx_pulse_p2 ),
		.i_osm_req_tx_pulse_p3   (i_osm_req_tx_pulse_p3  ),
		.i_osm_resp_rx_pulse_p3  (i_osm_resp_rx_pulse_p3 ),
		.i_osm_req_tx_pulse_p4   (i_osm_req_tx_pulse_p4  ),
		.i_osm_resp_rx_pulse_p4  (i_osm_resp_rx_pulse_p4 ),
		.i_osm_req_tx_pulse_p5   (i_osm_req_tx_pulse_p5  ),
		.i_osm_resp_rx_pulse_p5  (i_osm_resp_rx_pulse_p5 ),
		.i_osm_req_tx_pulse_p6   (i_osm_req_tx_pulse_p6  ),
		.i_osm_resp_rx_pulse_p6  (i_osm_resp_rx_pulse_p6 ),
		.i_osm_req_tx_pulse_p7   (i_osm_req_tx_pulse_p7  ),
		.i_osm_resp_rx_pulse_p7  (i_osm_resp_rx_pulse_p7 ),
		.i_osm_req_tx_pulse_p8   (i_osm_req_tx_pulse_p8  ),
		.i_osm_resp_rx_pulse_p8  (i_osm_resp_rx_pulse_p8 ),
		.i_osm_req_tx_pulse_p9   (i_osm_req_tx_pulse_p9  ),
		.i_osm_resp_rx_pulse_p9  (i_osm_resp_rx_pulse_p9 ),
		.i_osm_req_tx_pulse_p10  (i_osm_req_tx_pulse_p10 ),
		.i_osm_resp_rx_pulse_p10 (i_osm_resp_rx_pulse_p10),
		.i_osm_req_tx_pulse_p11  (i_osm_req_tx_pulse_p11 ),
		.i_osm_resp_rx_pulse_p11 (i_osm_resp_rx_pulse_p11),
		.i_osm_req_tx_pulse_p12  (i_osm_req_tx_pulse_p12 ),
		.i_osm_resp_rx_pulse_p12 (i_osm_resp_rx_pulse_p12),
		.i_osm_req_tx_pulse_p13  (i_osm_req_tx_pulse_p13 ),
		.i_osm_resp_rx_pulse_p13 (i_osm_resp_rx_pulse_p13),
		.i_osm_req_tx_pulse_p14  (i_osm_req_tx_pulse_p14 ),
		.i_osm_resp_rx_pulse_p14 (i_osm_resp_rx_pulse_p14),
		.i_osm_req_tx_pulse_p15  (i_osm_req_tx_pulse_p15 ),
		.i_osm_resp_rx_pulse_p15 (i_osm_resp_rx_pulse_p15),
		.i_osm_req_tx_pulse_p16  (i_osm_req_tx_pulse_p16 ),
		.i_osm_resp_rx_pulse_p16 (i_osm_resp_rx_pulse_p16),
		.i_osm_req_tx_pulse_p17  (i_osm_req_tx_pulse_p17 ),
		.i_osm_resp_rx_pulse_p17 (i_osm_resp_rx_pulse_p17),
		.i_osm_req_tx_pulse_p18  (i_osm_req_tx_pulse_p18 ),
		.i_osm_resp_rx_pulse_p18 (i_osm_resp_rx_pulse_p18),
		.i_osm_req_tx_pulse_p19  (i_osm_req_tx_pulse_p19 ),
		.i_osm_resp_rx_pulse_p19 (i_osm_resp_rx_pulse_p19),
		.i_osm_req_tx_pulse_p20  (i_osm_req_tx_pulse_p20 ),
		.i_osm_resp_rx_pulse_p20 (i_osm_resp_rx_pulse_p20),
		.i_osm_req_tx_pulse_p21  (i_osm_req_tx_pulse_p21 ),
		.i_osm_resp_rx_pulse_p21 (i_osm_resp_rx_pulse_p21),
		.i_osm_req_tx_pulse_p22  (i_osm_req_tx_pulse_p22 ),
		.i_osm_resp_rx_pulse_p22 (i_osm_resp_rx_pulse_p22),
		.i_osm_req_tx_pulse_p23  (i_osm_req_tx_pulse_p23 ),
		.i_osm_resp_rx_pulse_p23 (i_osm_resp_rx_pulse_p23),
		.i_osm_req_tx_pulse_p24  (i_osm_req_tx_pulse_p24 ),
		.i_osm_resp_rx_pulse_p24 (i_osm_resp_rx_pulse_p24),	
		.i_osm_req_tx_pulse_p25  (i_osm_req_tx_pulse_p25 ),
		.i_osm_resp_rx_pulse_p25 (i_osm_resp_rx_pulse_p25),
		.i_osm_req_tx_pulse_p26  (i_osm_req_tx_pulse_p26 ),
		.i_osm_resp_rx_pulse_p26 (i_osm_resp_rx_pulse_p26),
		.i_osm_req_tx_pulse_p27  (i_osm_req_tx_pulse_p27 ),
		.i_osm_resp_rx_pulse_p27 (i_osm_resp_rx_pulse_p27),
		.i_osm_req_tx_pulse_p28  (i_osm_req_tx_pulse_p28 ),
		.i_osm_resp_rx_pulse_p28 (i_osm_resp_rx_pulse_p28),
		.i_osm_req_tx_pulse_p29  (i_osm_req_tx_pulse_p29 ),
		.i_osm_resp_rx_pulse_p29 (i_osm_resp_rx_pulse_p29),
		.i_osm_req_tx_pulse_p30  (i_osm_req_tx_pulse_p30 ),
		.i_osm_resp_rx_pulse_p30 (i_osm_resp_rx_pulse_p30),
		.i_osm_req_tx_pulse_p31  (i_osm_req_tx_pulse_p31 ),
		.i_osm_resp_rx_pulse_p31 (i_osm_resp_rx_pulse_p31),		
 
        .ov_t1                   (wv_t1_itr2ldc     ),	
        .ov_t4                   (wv_t4_itr2ldc     ),	
        .ov_port_id              (wv_port_id_itr2ldc),			
        .o_t1_valid              (w_t1_valid_itr2ldc),
		.o_t4_valid              (w_t4_valid_itr2ldc)
);

link_delay_calculate  link_delay_calculate_inst
(
        .i_clk                  (i_clk  ),
        .i_rst_n                (i_rst_n),
	 
        .iv_t1                  (wv_t1_itr2ldc     ),
        .i_t1_valid             (w_t1_valid_itr2ldc),		
        .iv_t4                  (wv_t4_itr2ldc     ),
        .i_t4_valid             (w_t4_valid_itr2ldc),		
        .iv_t1t4_port_id        (wv_port_id_itr2ldc),
	 
        .iv_t2                  (wv_t2_ipp2ldc    ),  
        .i_t2_valid             (w_t2_wr_ipp2ldc  ),  		
        .iv_t3                  (wv_t3_ipp2ldc    ),
        .i_t3_valid             (w_t3_wr_ipp2ldc  ),		
        .iv_t2t3_port_id        (wv_osm_id_ipp2ope),
		.i_pdelay_pkt_waittimeout_flag(w_pdelay_pkt_waittimeout_flag_ipp2ldc),
		 
		.ov_t1                  (ov_t1                ),
		.ov_t2                  (ov_t2                ),
		.ov_t3                  (ov_t3                ),
		.ov_t4                  (ov_t4                ),
		.ov_timestamps_port_id  (ov_timestamps_port_id),
		.o_timestamps_valid     (o_timestamps_valid   ),
		 
		.ov_link_delay          (ov_link_delay        ),
		.ov_link_delay_id       (ov_link_delay_id     ),
        .o_link_delay_valid     (o_link_delay_valid   )		
		
);

opensync_protocol_decapsulate opensync_protocol_decapsulate_inst
(
        .i_clk              (i_clk                   ),
        .i_rst_n            (i_rst_n                 ),
                                                     
        .iv_data            (iv_data           ),
        .i_data_wr          (i_data_wr         ),
         
        .ov_local_cnt_rx    ( ),
        .ov_eth_type        (wv_eth_type_opd2ipp    ), 
        .ov_tsmp_type       (wv_tsmp_type_opd2ipp   ),
        .ov_tsmp_subtype    (wv_tsmp_subtype_opd2ipp),
		.ov_osm_id          (wv_osm_id_opd2ipp),
                            
        .ov_data            (wv_data_opd2ipp      ),
		.o_data_wr          (w_data_wr_opd2ipp    )
    );
initiator_packet_process 
#(
.local_module_id(local_module_id),
.clk_period(clk_period)
)
initiator_packet_process_inst
(
        .i_clk                                 (i_clk  ),
        .i_rst_n                               (i_rst_n),
	    
	    .iv_measure_responder_wait_time        (iv_measure_responder_wait_time ),
	    .iv_port_ptp_enabled                   (iv_port_ptp_enabled            ),
	    							             
	    .i_measure_req                         (w_measure_req_irt2ipp),
	    
	    .iv_hcp_mid                            (iv_hcp_mid),
         
        .iv_data                               (wv_data_opd2ipp),
	    .i_data_wr                             (w_data_wr_opd2ipp),
	    .iv_eth_type                           (wv_eth_type_opd2ipp),
	    .iv_tsmp_type                          (wv_tsmp_type_opd2ipp),
	    .iv_tsmp_subtype                       (wv_tsmp_subtype_opd2ipp),
	    .iv_port_id                            (wv_osm_id_opd2ipp),
	    
	    .ov_data                               (wv_data_ipp2ope  ),
	    .o_data_wr                             (w_data_wr_ipp2ope),
	    .ov_measure_port_id                    (wv_osm_id_ipp2ope),
        .o_first_byte_valid                    (w_first_byte_valid_ipp2ope),
	     
	    .ov_measure_req_tx_cnt_p0              (ov_measure_req_tx_cnt_p0          ),
	    .ov_measure_resp_rx_timeout_cnt_p0     (ov_measure_resp_rx_timeout_cnt_p0 ),	
	    .ov_measure_req_tx_cnt_p1              (ov_measure_req_tx_cnt_p1          ),
	    .ov_measure_resp_rx_timeout_cnt_p1     (ov_measure_resp_rx_timeout_cnt_p1 ),	
	    .ov_measure_req_tx_cnt_p2              (ov_measure_req_tx_cnt_p2          ),
	    .ov_measure_resp_rx_timeout_cnt_p2     (ov_measure_resp_rx_timeout_cnt_p2 ),	
	    .ov_measure_req_tx_cnt_p3              (ov_measure_req_tx_cnt_p3          ),
	    .ov_measure_resp_rx_timeout_cnt_p3     (ov_measure_resp_rx_timeout_cnt_p3 ),	
	    .ov_measure_req_tx_cnt_p4              (ov_measure_req_tx_cnt_p4          ),
	    .ov_measure_resp_rx_timeout_cnt_p4     (ov_measure_resp_rx_timeout_cnt_p4 ),	
	    .ov_measure_req_tx_cnt_p5              (ov_measure_req_tx_cnt_p5          ),
	    .ov_measure_resp_rx_timeout_cnt_p5     (ov_measure_resp_rx_timeout_cnt_p5 ),	
	    .ov_measure_req_tx_cnt_p6              (ov_measure_req_tx_cnt_p6          ),
	    .ov_measure_resp_rx_timeout_cnt_p6     (ov_measure_resp_rx_timeout_cnt_p6 ),	
	    .ov_measure_req_tx_cnt_p7              (ov_measure_req_tx_cnt_p7          ),
	    .ov_measure_resp_rx_timeout_cnt_p7     (ov_measure_resp_rx_timeout_cnt_p7 ),	
	    .ov_measure_req_tx_cnt_p8              (ov_measure_req_tx_cnt_p8          ),
	    .ov_measure_resp_rx_timeout_cnt_p8     (ov_measure_resp_rx_timeout_cnt_p8 ),	
	    .ov_measure_req_tx_cnt_p9              (ov_measure_req_tx_cnt_p9          ),
	    .ov_measure_resp_rx_timeout_cnt_p9     (ov_measure_resp_rx_timeout_cnt_p9 ),	
	    .ov_measure_req_tx_cnt_p10             (ov_measure_req_tx_cnt_p10         ),
	    .ov_measure_resp_rx_timeout_cnt_p10    (ov_measure_resp_rx_timeout_cnt_p10),	
	    .ov_measure_req_tx_cnt_p11             (ov_measure_req_tx_cnt_p11         ),
	    .ov_measure_resp_rx_timeout_cnt_p11    (ov_measure_resp_rx_timeout_cnt_p11),	
	    .ov_measure_req_tx_cnt_p12             (ov_measure_req_tx_cnt_p12         ),
	    .ov_measure_resp_rx_timeout_cnt_p12    (ov_measure_resp_rx_timeout_cnt_p12),	
	    .ov_measure_req_tx_cnt_p13             (ov_measure_req_tx_cnt_p13         ),
	    .ov_measure_resp_rx_timeout_cnt_p13    (ov_measure_resp_rx_timeout_cnt_p13),	
	    .ov_measure_req_tx_cnt_p14             (ov_measure_req_tx_cnt_p14         ),
	    .ov_measure_resp_rx_timeout_cnt_p14    (ov_measure_resp_rx_timeout_cnt_p14),	
	    .ov_measure_req_tx_cnt_p15             (ov_measure_req_tx_cnt_p15         ),
	    .ov_measure_resp_rx_timeout_cnt_p15    (ov_measure_resp_rx_timeout_cnt_p15),	
	    .ov_measure_req_tx_cnt_p16             (ov_measure_req_tx_cnt_p16         ),
	    .ov_measure_resp_rx_timeout_cnt_p16    (ov_measure_resp_rx_timeout_cnt_p16),	
	    .ov_measure_req_tx_cnt_p17             (ov_measure_req_tx_cnt_p17         ),
	    .ov_measure_resp_rx_timeout_cnt_p17    (ov_measure_resp_rx_timeout_cnt_p17),	
	    .ov_measure_req_tx_cnt_p18             (ov_measure_req_tx_cnt_p18         ),
	    .ov_measure_resp_rx_timeout_cnt_p18    (ov_measure_resp_rx_timeout_cnt_p18),	
	    .ov_measure_req_tx_cnt_p19             (ov_measure_req_tx_cnt_p19         ),
	    .ov_measure_resp_rx_timeout_cnt_p19    (ov_measure_resp_rx_timeout_cnt_p19),	
	    .ov_measure_req_tx_cnt_p20             (ov_measure_req_tx_cnt_p20         ),
	    .ov_measure_resp_rx_timeout_cnt_p20    (ov_measure_resp_rx_timeout_cnt_p20),	
	    .ov_measure_req_tx_cnt_p21             (ov_measure_req_tx_cnt_p21         ),
	    .ov_measure_resp_rx_timeout_cnt_p21    (ov_measure_resp_rx_timeout_cnt_p21),	
	    .ov_measure_req_tx_cnt_p22             (ov_measure_req_tx_cnt_p22         ),
	    .ov_measure_resp_rx_timeout_cnt_p22    (ov_measure_resp_rx_timeout_cnt_p22),	
	    .ov_measure_req_tx_cnt_p23             (ov_measure_req_tx_cnt_p23         ),
	    .ov_measure_resp_rx_timeout_cnt_p23    (ov_measure_resp_rx_timeout_cnt_p23),
        .ov_measure_req_tx_cnt_p24             (ov_measure_req_tx_cnt_p24         ),
	    .ov_measure_resp_rx_timeout_cnt_p24    (ov_measure_resp_rx_timeout_cnt_p24),
        .ov_measure_req_tx_cnt_p25             (ov_measure_req_tx_cnt_p25         ),
	    .ov_measure_resp_rx_timeout_cnt_p25    (ov_measure_resp_rx_timeout_cnt_p25),
	    .ov_measure_req_tx_cnt_p26             (ov_measure_req_tx_cnt_p26         ),
	    .ov_measure_resp_rx_timeout_cnt_p26    (ov_measure_resp_rx_timeout_cnt_p26),
	    .ov_measure_req_tx_cnt_p27             (ov_measure_req_tx_cnt_p27         ),
	    .ov_measure_resp_rx_timeout_cnt_p27    (ov_measure_resp_rx_timeout_cnt_p27),
	    .ov_measure_req_tx_cnt_p28             (ov_measure_req_tx_cnt_p28         ),
	    .ov_measure_resp_rx_timeout_cnt_p28    (ov_measure_resp_rx_timeout_cnt_p28),
	    .ov_measure_req_tx_cnt_p29             (ov_measure_req_tx_cnt_p29         ),
	    .ov_measure_resp_rx_timeout_cnt_p29    (ov_measure_resp_rx_timeout_cnt_p29),
	    .ov_measure_req_tx_cnt_p30             (ov_measure_req_tx_cnt_p30         ),
	    .ov_measure_resp_rx_timeout_cnt_p30    (ov_measure_resp_rx_timeout_cnt_p30),
	    .ov_measure_req_tx_cnt_p31             (ov_measure_req_tx_cnt_p31         ),
	    .ov_measure_resp_rx_timeout_cnt_p31    (ov_measure_resp_rx_timeout_cnt_p31),	
        
	    .ov_t2                                 (wv_t2_ipp2ldc                        ),
	    .ov_t3                                 (wv_t3_ipp2ldc                        ),
	    .o_t2_wr                               (w_t2_wr_ipp2ldc                      ),
	    .o_t3_wr                               (w_t3_wr_ipp2ldc                      ),
		.o_pdelay_pkt_waittimeout_flag         (w_pdelay_pkt_waittimeout_flag_ipp2ldc),
        
        .ov_req_sequence                       (ov_req_sequence)
);

opensync_protocol_encapsulate 
#(
.osm_id(8'd0),
.local_module_id(local_module_id)
) 
opensync_protocol_encapsulate_mrq
(
        .i_clk                    (i_clk            ),
        .i_rst_n                  (i_rst_n          ),
        
        .iv_hcp_mid               (iv_hcp_mid                     ),
        .iv_opensync_dst_module_id({7'h0,wv_osm_id_ipp2ope + 1'b1}),
        
        .iv_data                  (wv_data_ipp2ope           ),
        .i_data_wr                (w_data_wr_ipp2ope         ),
		                          
		.iv_eth_type              (16'h88f7                  ),
		.iv_ptp_messagetype       (4'h2                      ),
        .iv_local_count_rx        (40'h0                     ),
        .i_diagest_wr             (w_first_byte_valid_ipp2ope),
                                  
        .ov_data                  (ov_data                   ),
        .o_data_wr                (o_data_wr                 )
);
endmodule